Texture2DとrawImageの関係について 您所在的位置:网站首页 unity RawImage texture Texture2DとrawImageの関係について

Texture2DとrawImageの関係について

2024-02-23 01:37| 来源: 网络整理| 查看: 265

すみません、まだ原因特定ができていない段階ですが、追記欄だとコードが見づらくなってしまうため回答欄を使わせていただきました。ご容赦ください。

「MaterialやColorは初期のまま」とのことですが、Planeの方もRawImageの方もデフォルトのまま...Planeのマテリアルは「Default-Material」、RawImageのマテリアルは「None (Material)」でColorは不透明な白ということでしょうか?

下記のようなコード(【Unity】Webカメラの画像を加工して表示する - おもちゃラボのWebCamControllerをベースにしました)のUpdate内に、ご提示いただいたTexture2D変換部分のコードを使用してみましたが、そのままの状態ではPlaneには映像が映りましたが、RawImageは完全透明になってしまいました。 rcの初期化部分をnew Color32()からnew Color32(0, 0, 0, byte.MaxValue)に変えて完全不透明にすることで正しくグレースケール化された映像が映ったのですが、ご質問者さんの場合はnew Color32()でも表示される、ただし映像は黄色っぽくなってしまう...という状況でしょうか。

C#

1using System.Collections; 2using UnityEngine; 3using UnityEngine.UI; 4 5namespace WebCamToTex2D 6{ 7 public class WebCamController : MonoBehaviour 8 { 9 public MeshRenderer DestinationMeshRenderer; 10 public RawImage DestinationRawImage; 11 private Color32[] colors; 12 private Texture2D texture; 13 private WebCamTexture webcamTexture; 14 15 private IEnumerator Start() 16 { 17 var devices = WebCamTexture.devices; 18 if ((this.DestinationMeshRenderer == null) || (this.DestinationRawImage == null) || (devices == null) || 19 (devices.Length 16) && (this.webcamTexture.height > 16)) 30 { 31 var w = this.webcamTexture.width; 32 var h = this.webcamTexture.height; 33 Debug.LogFormat("WebCamTexture size:({0}, {1})", w, h); 34 this.colors = new Color32[w * h]; 35 this.texture = new Texture2D(w, h, TextureFormat.RGBA32, false); 36 this.texture.name = "GrayTexture"; 37 this.DestinationMeshRenderer.material.mainTexture = this.texture; 38 this.DestinationRawImage.texture = this.texture; 39 break; 40 } 41 42 yield return null; 43 } 44 } 45 46 private void Update() 47 { 48 if (this.colors != null) 49 { 50 this.webcamTexture.GetPixels32(this.colors); 51 var width = this.webcamTexture.width; 52 var height = this.webcamTexture.height; 53 var rc = new Color32(0, 0, 0, byte.MaxValue); 54 for (var x = 0; x


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有